﻿using Siemens.Engineering.HW;
using Siemens.Engineering;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace TIA_Openness
{
    public class GetDevices
    {
        public static List<Device> list = new List<Device>();
        //Enamerate devices in groups or sub-groups
        public static void EnumerateDevicesInGroups(Project project)
        {

            foreach (DeviceUserGroup deviceUserGroup in project.DeviceGroups)
            {
                EnumerateDeviceUserGroup(deviceUserGroup);
            }
        }
        public static void EnumerateDeviceUserGroup(DeviceUserGroup deviceUserGroup)
        {
            EnumerateDeviceObjects(deviceUserGroup.Devices);
            foreach (DeviceUserGroup subDeviceUserGroup in deviceUserGroup.Groups)
            {
                // recursion 迭代
                EnumerateDeviceUserGroup(subDeviceUserGroup);
            }
        }
        public static void EnumerateDeviceObjects(DeviceComposition deviceComposition)
        {
            foreach (Device device in deviceComposition)
            {
                GetDevices.list.Add(device);
            }
        }
    }
}
